# -*- coding: utf-8 -*-
##

'''
source: Bruno Moreira, 6170
slightly changed
http://docs.python.org/library/simplehttpserver.html
'''
import threading
import SimpleHTTPServer
import SocketServer


class DifThread(threading.Thread):
    '''
    A subclass of threading.Thread
    '''
    def __init__(self, *args, **keywords):
        threading.Thread.__init__(self, *args, **keywords)
        pass
   
    def start(self):
        '''
        Start the thread.
        '''
        threading.Thread.start(self)
        pass
    pass


class HttpServer (threading.Thread):
    '''
    A class that opens an httpserver in a different thread
    '''
    
    def __init__(self, port):
        Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
        self.httpd = SocketServer.TCPServer(('', port), Handler)
        
        self.server = DifThread(target=self.start_server)
        self.server.start()
        pass

    def start_server(self):
        self.httpd.serve_forever()
        pass
    pass
